package com.example.baselib

import android.graphics.Canvas
import android.graphics.Color
import android.graphics.ColorFilter
import android.graphics.Paint
import android.graphics.PixelFormat
import android.graphics.drawable.Drawable

import androidx.annotation.IntRange
import com.example.baselib.constants.MyConstants

object WaterMarkBg : Drawable() {
    private val logo =MyConstants.userData.useridname+"-"+MyConstants.userData.username
    private val paint = Paint()
    override fun draw(canvas: Canvas) {
        val width = bounds.right
        val height = bounds.bottom
        canvas.drawColor(Color.parseColor("#F5F5F5"))
        paint.color = Color.parseColor("#AEAEAE")
        paint.isAntiAlias = true
        paint.textSize = 30f
        canvas.save()
        canvas.rotate(-30f)
        val textWidth = paint.measureText(logo)
        var index = 0
        var positionY = height / 10
        while (positionY <= height) {
            val fromX = -width + index++ % 2 * textWidth
            var positionX = fromX
            while (positionX < width) {
                canvas.drawText(logo, positionX, positionY.toFloat(), paint)
                positionX += textWidth * 4
            }
            positionY += height / 3
        }
        canvas.restore()
    }

    override fun setAlpha(@IntRange(from = 0, to = 255) alpha: Int) {

    }

    override fun setColorFilter(colorFilter: ColorFilter?) {

    }

    override fun getOpacity(): Int {
        return PixelFormat.UNKNOWN
    }

}
